<?php

namespace App\Mapper;

use App\Exception\BusinessException;
use App\Model\UserModel;

class UserMapper
{
    public static function existsOrFailByAccount($account){
        $exists = UserModel::where('account', $account)->exists();
        if($exists){
            throw new BusinessException("用户已存在");
        }
    }

    public static function existsOrFailByMobile($mobile){
        $exists = UserModel::where('mobile', $mobile)->exists();

        if ($exists) {
            throw new BusinessException('该手机号已注册');
        }
    }

    public static function createUserByAccount($account, $password){
        return UserModel::create([
            'account' => $account,
            'password' => $password
        ]);
    }

    public static function createUserByMobile($mobile){
        return UserModel::create([
            'mobile' => $mobile,
        ]);
    }
}